package com.test.pack1.demo.base1_4;

import edu.princeton.cs.algs4.BinarySearch;

import java.util.Arrays;

/**
 * Created by dws on 2017/11/27.
 *
 * 计算和为0的二元数组个数
 */
public class TwoSumFast {

    public static int count(int[] a){
        Arrays.sort(a);
        int N = a.length;
        int cnt = 0;
        for (int i = 0; i < N; i++) {
            if(BinarySearch.rank(-a[i],a)>i){
                cnt++;
            }
        }
        return cnt;
    }

}
